package drops.gui;

import java.util.*;
import java.text.*;

public class MonthView {
    
    public final static int dom[] = {
        31, 28, 31,  /* jan, feb, mar */
        30, 31, 30,  /* apr, may, jun */
        31, 31, 30,  /* jul, aug, sep */
        31, 30, 31   /* oct, nov, dec */
    };

	
    public MonthView() {
    }
    
    public Vector printMonth(int mm, int yy) {

        int leadSpaces = 0;
        Vector numbers = new Vector();
        Vector rowData = new Vector();

        if (mm < 0 || mm > 11) {
            throw new IllegalArgumentException(
                "Month " + mm + " bad, must be 0-11");
        }

        GregorianCalendar cal = new GregorianCalendar(yy, mm, 1);

        leadSpaces = cal.get(Calendar.DAY_OF_WEEK)-1;

        int daysInMonth = dom[mm];

        if (cal.isLeapYear(cal.get(Calendar.YEAR)) && mm == 1) {
            ++daysInMonth;
        }
        
        int j=0;
        for (int i = 0; i < leadSpaces; i++) {
            j++;
            rowData.add("   ");
            if (j==7) {
            	j=0;
            	numbers.add(rowData);
            	rowData = new Vector();
            }
        }
        for (int i = 1; i <= daysInMonth; i++) {
            j++;
            rowData.add(i);
            if (j==7) {
            	j=0;
            	numbers.add(rowData);
            	rowData = new Vector();
            }
        }
        numbers.add(rowData);
        return numbers;
    }
    
     public String getMonth(int mm) {
     	String month=null;
     	
     	if(mm==0){month = new String("January");}
     	if(mm==1){month = new String("February");}
     	if(mm==2){month = new String("March");}
     	if(mm==3){month = new String("April");}
     	if(mm==4){month = new String("May");}
     	if(mm==5){month = new String("June");}
     	if(mm==6){month = new String("July");}
     	if(mm==7){month = new String("August");}
     	if(mm==8){month = new String("September");}
     	if(mm==9){month = new String("October");}
     	if(mm==10){month = new String("November");}
     	if(mm==11){month = new String("December");}
     	
     	return month;
     }
}